package pers.liyan.shi.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.liyan.shi.springboot.bean.Employee;
import pers.liyan.shi.springboot.service.EmployeeService;

@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService service;

    @GetMapping("/emp/{id}")
    public Employee getEmp(@PathVariable("id") Integer id){
        return service.getEmpById(id);
    }

    @PutMapping("/emp")
    public Employee updateEmp(Employee employee){
        Employee result = service.updateEmp(employee);
        return result;
    }

    @DeleteMapping("/emp/{id}")
    public String deleteEmp(@PathVariable("id") Integer id){

        service.deleteEmp(id);

        return "SUCCESS";

    }

    @GetMapping("/emp/lastName/{lastName}")
    public Employee getEmpByLastName(@PathVariable("lastName") String lastName){
        return service.getEmpByLastName(lastName);
    }

}

